refactor: clean up SessionPhase after code review#27
Merged
Conversation
- Move forward-compat fallback into SessionPhase.init(from:) so callers use typed decodeIfPresent instead of a String→rawValue detour - Guard pause()/resume() before writing to avoid spurious @observable notifications when phase is already in the target state - Remove duplicate // MARK: Lifecycle property marker (methods section already carries the canonical MARK) - Replace force-unwrap in tests with try #require per project convention
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SessionPhase.Codable: moved the forward-compatibility fallback (unknown raw value →.running) into a custominit(from:)onSessionPhaseitself, soEncounterSession's decoder can usedecodeIfPresent(SessionPhase.self, …)instead of a stringly-typedString → rawValuedetourpause()/resume(): guard on current value before writing to avoid spurious@Observablenotifications when the phase is already in the target state (consistent with other mutating methods in the file)// MARK: Lifecycle(no-dash property marker) was redundant alongside// MARK: - Lifecyclefor the methods sectionjson.data(using: .utf8)!withtry #require(…)in the two Codable edge-case tests per project conventionTest plan
swift test --filter DHKitTestspasses (101 tests, 14 suites)SessionPhaseTests— all phase transition, idempotency, and Codable round-trip cases greenmissingPhaseKeyDecodesAsRunningandunknownFuturePhaseValueDecodesAsRunningstill green with the newSessionPhase.init(from:)implementation